// Based on example given at:
// http://lazyfoo.net/SDL_tutorials/lesson13/index.php by Lazy Foo
// -NFigg

#ifndef _TIMER_H_
#define _TIMER_H_

#include "SDL.h"
#include <string>
#include "id_component.h"

class Timer;
typedef void (*TimerCallback)(void*, Timer*);

//Use this value to have an infinite timer, so it doesn't stop.
#define PD_TIMER_INFINITE -1

//The timer
class Timer
{
private:
	//The timer status
	bool paused, inactive, repeat;
	double time, timeSpan;
	Uint16 repeatCount, repeatTarget;

	//Callback to function
    TimerCallback callback;
	void *callbackParam;
public:
	//Initializes variables
	Timer(double timerLength);
	~Timer();

	//Public id component - for id and tag support
	IdComponent idComponent;

	//The various clock actions
	void start();
	void stop();
	void pause();
	void unpause();
    
	//Gets the timer's time
	double get_time();
	void update(double timeDelta);
	void set_callback(TimerCallback cb, void* cbParam);
	TimerCallback get_callback();
	void set_repeat(bool rpt);
	bool get_repeat();
	void set_timespan(double span);
	double get_timespan();
    
	//Checks the status of the timer
	bool is_inactive();
	bool is_paused();

	static Timer* CountdownTimer(double timeSpan);
	static Timer* RepeatTimer(double timeSpan, int repeatCount);
};

#endif